/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

//==============================================สร้าง Date picker======================================================
 function MakeDatepicker(holder) {
    $.datepicker.setDefaults($.datepicker.regional['en']);
    var yearRange ='c-50:c+5';
    var maxDate='';
    var minDate='';
    //$(".ajax-content").find("div.page-name").find(".pickdate").datepickerThai({
    if (holder !== "") {
        $(holder).find(".pickdate").each(function(){
            if($(this).hasClass("hasDatepicker"))
            {}
            else if($(this).hasClass("disableDatePicker")){
                $(this).attr("readOnly","readOnly");
                $(this).addClass("input-readOnly");
            }else{
                var yearRange = ($(this).attr("yearRange") == undefined) ? "" : $(this).attr("yearRange");
                maxDate= ($(this).attr("maxdate") == undefined) ? "" : $(this).attr("maxdate");
                if($(this).attr("mindate") != undefined){
                    if(($(this).attr("mindate") != "")){
                        minDate = "-"+$(this).attr("mindate");
                    }else{
                        minDate = '';
                    }
                }
                var onChange = ($(this).attr("onChange") == undefined) ? null : $(this).attr("onChange");
                $(this).datepicker({
                    changeMonth: true,
                    changeYear: true,
                    showOn: 'both',
                    dateFormat: "dd/mm/yy",
                    buttonImage: 'Content/Images/iconCalendar.png',
                    yearRange: yearRange,
                    buttonImageOnly: true,
                    maxDate: maxDate,
                    minDate: minDate,
                    autoSize: true,
                    onClose: function (dateText, inst) {
                        $(this).removeAttr("title").nextAll("div.validateMes:first").remove();
                        if(onChange != undefined && onChange != ""){
                            eval(onChange)($(this));
                        }
                    },
                    beforeShow: function() {
                        if($(this).hasClass("disableControl") == true){
                            return false;
//                            setTimeout(function(){
//                                $('#ui-datepicker-div').hide();
//                            }, 0);
                        }else{
                            setTimeout(function(){
                                $('.ui-datepicker').css('z-index', 99999999999999);
                            }, 0);
                        }
                    }
                });
            }
        });
    } else {
        $(".pickdate").datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: 'both',
            dateFormat: "dd/mm/yy",
            buttonImage: 'Content/Images/iconCalendar.png',
            yearRange: yearRange,
            buttonImageOnly: true,
            maxDate: maxDate,
            autoSize: true,
            onClose: function (dateText, inst) {
                $(this).removeAttr("title").nextAll("div.validateMes:first").remove();
            },
            beforeShow: function() {
                if($(this).hasClass("disableControl") == true){
                    return false;
//                            setTimeout(function(){
//                                $('#ui-datepicker-div').hide();
//                            }, 0);
                }else{
                    setTimeout(function(){
                        $('.ui-datepicker').css('z-index', 99999999999999);
                    }, 0);
                }
            }
        });
    }
    $("#ui-datepicker-div").hide();
}
function closeDlgFrame(dlg) {
    var dlgTemp = $('#' + dlg);
    //var dlgTemp = $(dlg);
    dlgTemp.dialog('close');
}
function formatDate(d) {
    var dd = d.getDate()
    if ( dd < 10 ) dd = '0' + dd

    var mm = d.getMonth()
    if ( mm < 10 ) mm = '0' + mm

    var yy = d.getFullYear()
    if ( yy < 10 ) yy = '0' + yy

    return dd+'/'+mm+'/'+yy
}

function formatDateTime(d) {
    var dd = d.getDate()
    if ( dd < 10 ) dd = '0' + dd

    var mm = d.getMonth() + 1
    if ( mm < 10 ) mm = '0' + mm

    var yy = d.getFullYear()
    if ( yy < 10 ) yy = '0' + yy

    var hh = d.getHours();
    if ( hh < 10 ) hh = '0' + hh

    var mn = d.getMinutes();
    if ( mn < 10 ) mn = '0' + mn

    var ss = d.getSeconds();
    if ( ss < 10 ) ss = '0' + ss

    return dd+'/'+mm+'/'+yy + " " + hh + ":" + mn +":" + ss;
}


